<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\ChannelService\ChannelService;
use Hyperf\Di\Annotation\Inject;

/**
 * SBBC渠道分销
 * @author huj
 * @Controller(prefix="/webapi/v1/channel")
 * @Middleware(WebApiMiddleware::class)
 */
class ChannelController extends AbstractController
{
    /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var ChannelService
     */
    protected $channelService;

    /**
     * 渠道分销首页数据
     * @RequestMapping(path="index", methods="get,post")
     */
    public function index(RequestInterface $request)
    {
        $param        = $request->inputs(['cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->getChannelInfo($param);
    }

    /**
     * 分销用户，下游Q店
     * @RequestMapping(path="qStore", methods="get,post")
     */
    public function qStore(RequestInterface $request)
    {
        $param        = $request->inputs(['key_word','page','limit']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->getStore($param);
    }

    /**
     * 渠道商品列表
     * @RequestMapping(path="goodsList", methods="get,post")
     */
    public function goodsList(RequestInterface $request)
    {
        $param        = $request->inputs(['limit','mid','page','key_word','status','class_id','cid','mnid','sortField','sort','price_min','price_max']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->getChannelGoods($param);
    }

    /**
     * 渠道商品详情
     * @RequestMapping(path="goodsDetail", methods="get,post")
     */
    public function goodsDetail(RequestInterface $request)
    {
        $param        = $request->inputs(['mnid','goods_id','cid','spec_num']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->goodsDetail($param);
    }

    /**
     * 提现审核列表
     * @RequestMapping(path="withdrawList", methods="get,post")
     */
    public function withdrawList(RequestInterface $request)
    {
        $param        = $request->inputs(['key_word','limit','page']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->withdrawList($param);
    }

    /**
     * 小b分享配置
     * @RequestMapping(path="getShare", methods="get,post")
     */
    public function getShare(RequestInterface $request)
    {
        $param        = $request->inputs(['cid','mnid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->getShare($param);
    }

    /**
     * 渠道小程序banner
     * @RequestMapping(path="banner", methods="get,post")
     */
    public function banner(RequestInterface $request)
    {
        $param        = $request->inputs(['cid','mnid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->banner($param);
    }

    /**
     * 专题商品列表
     * @RequestMapping(path="topicGoods", methods="get,post")
     */
    public function topicGoods(RequestInterface $request)
    {
        $param        = $request->inputs(['mnid','cid','topic_id','page','limit','type']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->topicGoods($param);
    }

    /**
     * 首页推荐栏标题及商品
     * @RequestMapping(path="choiceGoodsLists", methods="get,post")
     */
    public function choiceGoodsLists(RequestInterface $request)
    {
        $param        = $request->inputs(['mnid','cid','page','limit']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->choiceGoodsLists($param);
    }

    /**
     * 小B首页内容（banner/组件）
     * @RequestMapping(path="HomePage", methods="get,post")
     */
    public function homePage(RequestInterface $request)
    {
        $param        = $request->inputs(['mnid','cid','mn_sid','adv_temp']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->homePage($param);
    }

    /**
     * 获取首页tab页内容
     * @RequestMapping(path="getTabContent", methods="get,post")
     */
    public function getTabContent(RequestInterface $request)
    {
        $param        = $request->inputs(['mnid','cid','mn_sid','tab_id']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->getTabContent($param);
    }

    /**
     * 获取商品分组
     * @RequestMapping(path="getGoodsGroup", methods="get,post")
     */
    public function getGoodsGroup(RequestInterface $request)
    {
        $param        = $request->inputs(['mnid','cid','mn_sid','tab_id','tool_id','id','page','limit']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->getGoodsGroup($param);
    }

    /**
     * 品牌商品列表
     * @RequestMapping(path="brandList", methods="get,post")
     */
    public function brandList(RequestInterface $request)
    {
        $param        = $request->inputs(['mnid','cid','page','limit','brand_id','goods_name']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->brandGoodsList($param);
    }

    /**
     * 设置自动上架
     * @RequestMapping(path="autoUp", methods="get,post")
     */
    public function autoUp(RequestInterface $request)
    {
        $param        = $request->inputs(['mnid','status','cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->autoUp($param);
    }

    /**
     * 添加历史进货单
     * @RequestMapping(path="addHistoryOrder", methods="get,post")
     */
    public function addHistoryOrder(RequestInterface $request)
    {
        $param        = $request->inputs(['sn','cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->addHistoryOrder($param);
    }

    /**
     * 历史进货单列表
     * @RequestMapping(path="historyOrderList", methods="get,post")
     */
    public function historyOrderList(RequestInterface $request)
    {
        $param        = $request->inputs(['page','cid','limit']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->historyOrderList($param);
    }

    /**
     * 修改进货单名称
     * @RequestMapping(path="editHistoryOrderName", methods="get,post")
     */
    public function editHistoryOrderName(RequestInterface $request)
    {
        $param        = $request->inputs(['history_id','cid','new_name']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->editHistoryOrderName($param);
    }

    /**
     * 删除历史进货单
     * @RequestMapping(path="delHistoryOrder", methods="get,post")
     */
    public function delHistoryOrder(RequestInterface $request)
    {
        $param        = $request->inputs(['history_id','cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->channelService->delHistoryOrder($param);
    }
}